def pop_list(stack):
    l = []
    while stack[-1] != '[':
        l.append(stack.pop(-1))
    stack.pop(-1)
    l.reverse()
    return l


def parsed_ast_stack(token_list):
    """
    Stack-based parsing of AST.
    """
    l = []
    i = 0
    while i < len(token_list):
        token = token_list[i]
        i += 1
        if token == ']':
            list_token = pop_list(l)
            l.append(list_token)
        else:
            l.append(token)
    return l


def main_parsed_ast_stack():
    tokens1 = ['[', '+', 12, '[', '-', 23, 45, ']', ']']
    tokens2 = ['[', '+', 12, '[', '-', 23, 45, ']', ']']
    parsed_result = parsed_ast_stack(tokens1 + tokens2)
    print('Stack parse result:', parsed_result)


if __name__ == '__main__':
    main_parsed_ast_stack()
